<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			let students = []; 
			function init(){
				let xhr = new XMLHttpRequest();
				xhr.open("GET","stus.xml",false);
				xhr.send();
				var xmldata = xhr.responseXML;
				students = xmldata.querySelectorAll("student");
				document.getElementById("num").value = students[0].getAttribute("sno");
				document.getElementById("sname").value = students[0].getAttribute("sname");
				
			}
		</script>
	</head>
	<body onload="init()">
		学号：<input type="text" id="num">
		<br>
		姓名：<input type="text" id="sname"/>
		<button type="button">下一个</button>
		<script type="text/javascript">
		    let n=1
			document.querySelector("button").onclick=function(){
				n++
				if(n>students.length){
					n=1//第n个学生
				}
				document.getElementById("num").value = students[n-1].getAttribute("sno");
				document.getElementById("sname").value = students[n-1].getAttribute("sname");
			}
		</script>
	</body>
</html>
